package org.linlinjava.litemall.db.service;

import java.time.LocalDateTime;
import java.util.List;

import javax.annotation.Resource;

import org.linlinjava.litemall.db.dao.LitemallUserHerbApproveItemMapper;
import org.linlinjava.litemall.db.domain.LitemallUserHerbApproveItem;
import org.linlinjava.litemall.db.domain.LitemallUserHerbApproveItemExample;
import org.springframework.stereotype.Service;

@Service
public class LitemallUserHerbApproveItemService {

    @Resource
    private LitemallUserHerbApproveItemMapper userHerbApproveMapper;

    public LitemallUserHerbApproveItem findById(Integer userId) {
        return userHerbApproveMapper.selectByPrimaryKey(userId);
    }

    public void add(LitemallUserHerbApproveItem userHerb) {
    	userHerb.setAddTime(LocalDateTime.now());
    	userHerb.setUpdateTime(LocalDateTime.now());
        userHerbApproveMapper.insertSelective(userHerb);
    }

    public void addAll(List<LitemallUserHerbApproveItem> itemList) {
        userHerbApproveMapper.batchInsert(itemList);
    }

    public int updateById(LitemallUserHerbApproveItem userHerb) {
    	userHerb.setUpdateTime(LocalDateTime.now());
        return userHerbApproveMapper.updateByPrimaryKeySelective(userHerb);
    }

    public int count() {
    	LitemallUserHerbApproveItemExample example = new LitemallUserHerbApproveItemExample();
        example.or().andDeletedEqualTo(false);

        return (int) userHerbApproveMapper.countByExample(example);
    }

    public List<LitemallUserHerbApproveItem> queryByUserApproveId(Integer userApproveId) {
    	LitemallUserHerbApproveItemExample example = new LitemallUserHerbApproveItemExample();
        example.or().andUserApproveIdEqualTo(userApproveId).andDeletedEqualTo(false);
        return userHerbApproveMapper.selectByExample(example);
    }

    public void deleteById(Integer id) {
    	userHerbApproveMapper.logicalDeleteByPrimaryKey(id);
    }
}
